import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.*;

public class TestCallable2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("主线程开始执行...");

        ExecutorService executorService = Executors.newFixedThreadPool(5);

        LinkedList<Callable<Integer>> callableLinkedList = new LinkedList<>();

        for (int i = 0; i < 5; i++) {
            CallableExample callableExample = new CallableExample();
            callableLinkedList.add(callableExample);
        }

        // 执行所有线程的任务
        List<Future<Integer>> futureList = executorService.invokeAll(callableLinkedList);

        for (Future<Integer> item : futureList) {
            System.out.println("结果是：" + item.get());
        }

        executorService.shutdown();
    }


}
